class Admin::ProductSupplementsController < Admin::AdminController
  before_filter :load_product, :load_breadcrumbs

  filter_access_to :all

  def index
    @search = @product.supplements.search(params[:search])
  end

  def new
    respond_to do |format|
      format.html
      format.js {render :action => :new, :layout => false}
    end
  end

  def create
    if @product.supplements.new(params[:supplement]).save
      redirect_to admin_product_product_supplements_path(:product_id => @product.id), :notice => "Příloha byla úspěšně nahrána."
    else
      render :action => :new
    end
  end

  def edit
    @product_supplement = Supplement.find(params[:id])
    
    respond_to do |format|
      format.html
      format.js {render :action => :edit, :layout => false}
    end
  end

  def update
    if Asset.find(params[:id]).update_attributes(params[:supplement])
      redirect_to admin_product_product_supplements_path(:product_id => @product.id), :notice => "Příloha byla úspěšně upravena."
    else
      render :action => :edit
    end
  end

  def move

  end

  private
  def load_product
    @product_supplement = Supplement.new(params[:supplement])
    @product = Product.find(params[:product_id])
  end

  def load_breadcrumbs
    #add_crumb("Správa výrobků", admin_products_path)
    #add_crumb("Editace výrobku", edit_admin_product_path(params[:product_id]))
    #add_crumb("Správa jednotek", :only => :index) {}
    #add_crumb("Správa příloh", admin_product_product_supplements_path(params[:product_id]), :except => :index)
    #add_crumb("Nová příloha", :only => [:new, :create]) {}
    #add_crumb("Editace přílohy", :only => [:edit, :update]) {}
  end
end